import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Shop } from './shop.shcema'
import { Model } from 'mongoose'
@Injectable()
export class ShopService {
    // 模型注入
    constructor(@InjectModel(Shop.name) private ShopSchema: Model<Shop>) {
    }
    //添加品牌
    async addShop(body: any) {
        await this.ShopSchema.create(body)
        return "添加成功"
    }
    //查询品牌
    async getShop(searchList:any[]) {
        let data 
        if (searchList.length > 0) {
            data = await this.ShopSchema.find({ $and: searchList }) // 使用

        } else {
            data = await this.ShopSchema.find() // 使用
        }

        return data
    }
    //修改品牌
    async updateShop(body: any) {
        await this.ShopSchema.updateOne({ _id: body._id }, body)
        return  "修改成功"
    } 
    //删除品牌
    async deleteShop(body: any) {
        await this.ShopSchema.deleteOne({ _id: body._id })
        return "删除成功"
    }

    
}  